# -*- coding: utf-8 -*-
'''
@author: Hugo
@file: main.py
@time: 2021/8/15 15:53
'''
from icecream import ic
import datetime
import time
from flask import Flask,render_template,request,make_response
app = Flask(__name__)
from hashlib import md5
def md(content):
    m = md5()
    m.update(content.encode(encoding='utf8'))
    str_md5 = m.hexdigest()
    return str_md5

def parse(tim,sign):
    sale = tim + 'feifei'
    token = md(sale)
    ic(token)
    if sign == token:
        return True
    else:
        return False

@app.after_request
def ccc(res):
    res.set_cookie('name','wyh'),
    return res

@app.route('/')
def index():
    # res = make_response('ff')
    # res.set_cookie('name','wyh')
    return render_template('feifei.html')
    return res

def delas(tp):
    tamp = int(tp)
    now = round(int(time.time()))
    ic(now)
    ic(tamp)
    dela = datetime.datetime.fromtimestamp(now) - datetime.datetime.fromtimestamp(tamp)
    ic(datetime.datetime.fromtimestamp(now))
    ic(datetime.datetime.fromtimestamp(tamp))
    # ic(dela.total_seconds())
    return dela.total_seconds()

@app.route('/api')
def detil():
    t = request.cookies.get('per')
    token = request.cookies.get('__zp_stoken__')
    ic(parse(t,token))
    ic(t,token)
    ic(delas(t))
    if not all([t,token]):
        return '你是一个爬虫'
    if parse(t,token)==True and delas(t) < 60:
        return render_template('demo.html')

if __name__ == '__main__':
    app.run()